/**
 * 水果对象池
 */
class FruitPool{
    private static FruitList:fruit[] = [];
    constructor()
    {

    }

    public static getFruit(data):fruit
    {
        let _fruit:fruit;
        let list = FruitPool.FruitList;
        if(list.length > 0)
        {
            _fruit = list.shift();
            _fruit.setUI(data);
        }
        else
        {  
            _fruit = new fruit(data);
        }
        return _fruit;
    }

    public static pushFruit(fruit)
    {
        if(fruit && FruitPool.FruitList.indexOf(fruit) == -1)
        {
            FruitPool.FruitList.push(fruit);
        }
    }

    public static getLength()
    {
        return FruitPool.FruitList.length;
    }

    public static clearPool()
    {
        let list = FruitPool.FruitList;
        let len = list.length;
        if(len > 0)
        {
            for(let i=0;i<len;i++)
            {
                let fruit = list[i] as fruit;
                list.splice(i,1);
                fruit.remove();
                fruit = null;
                i--;
                len--;
            }
        }
        
        FruitPool.FruitList = [];
    }
}